package cheme.ProcessModel.Cmds;

import cheme.ProcessModel.IChild;
import cheme.ProcessModel.IParent;


public class DeleteCmd extends ChemeCommand
{
	private IParent parent;
	private IChild child;
	
	int insertIndex = -1;
	
	public DeleteCmd(IChild child)
	{
		super(child, "Delete command");
		this.child = child;
	}

	@Override
	protected void primExecute()
	{
		parent = child.getParent();
		insertIndex = parent.indexOf(child);
		
		parent.remove(child);
	}
	
	@Override
	protected void primRedo()
	{
		parent.remove(child);
	}

	@Override
	protected void primUndo()
	{
		parent.add(child, insertIndex);
	}
}